<template>
	<view>

		<view class="list" v-if="item.mode==='more'" v-for=" (item,index) in info " :key="index">
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-orange"></text>
					审核
				</view>
				<view class="action pass">
					<view class="cu-form-group btn">
						<view>
							<button @click="pass('通过',item._id,index)" class="cu-btn round line-green ">通过</button>
							<button @click="pass('不通过',item._id,index)" class="cu-btn round line-red margin-left-sm">不通过</button>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-card article no-card" @click="open(item)">
				<view class="cu-item shadow">
					<view class="title flex">
						<view class="listcard-header_image cu-avatar lg">
							<image v-if="!item.avatar" src="../../static/img/guo.jpg"></image>
							<image :src="item.avatar"></image>
						</view>
						<view style="margin-left: 4%;">{{item.name}}</view>
					</view>
					<view class="title">
						<view class="text-cut">{{item.title}}</view>
					</view>

					<view class=" contentmore">
						<!-- <image :src="item.pic[0]"></image> -->
						<view style="display: flex; margin-top: 10px;width: 100%;height: 100px;padding: 0;padding: 2%;">
							<view v-if="index<3" v-for="(ite,index) in item.pic" :key="ite" class="listcard-image_item">
								<image :src="ite" style="width: 100%;height: 100%; border-radius: 5px;"></image>
							</view>
						</view>
						<view class="desc" style="margin-top: 5%;">
							<view class="text-contents">{{item.content}} </view>
							<view class="time">
								<view class="cu-tag bg-red light sm round">发表时间：</view>
								<view class="cu-tag  light sm round">{{item.time|unix2Time}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="list" v-if="item.mode==='one'" v-for=" (item,index) in info " :key="index">
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-orange"></text>
					审核
				</view>
				<view class="action pass">
					<view class="cu-form-group btn">
						<view>
							<button @click="pass('通过',item._id,index)" class="cu-btn round line-green ">通过</button>
							<button @click="pass('不通过',item._id,index)" class="cu-btn round line-red margin-left-sm">不通过</button>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-card article no-card" @click="open(item)">
				<view class="cu-item shadow">
					<view class="title flex">
						<view class="listcard-header_image cu-avatar lg">
							<image v-if="!item.avatar" src="../../static/img/guo.jpg"></image>
							<image :src="item.avatar"></image>
						</view>
						<view style="margin-left: 4%;">{{item.name}}</view>
					</view>
					<view class="title">
						<view class="text-cut">{{item.title}}</view>
					</view>
					<view class="content">
						<image :src="item.pic[0]"></image>
						<view class="desc">
							<view class="text-contents">{{item.content}} </view>
							<view style="padding-top: 5%;">
								<view class="cu-tag  light sm round" style="float: right;">{{item.time|unix2Time}}</view>
								<view class="cu-tag bg-red light sm round" style="float: right;">发表时间：</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="list" v-if="item.mode==='no'" v-for=" (item,index) in info " :key="index">
			<view class="cu-bar bg-white solid-bottom margin-top">
				<view class="action">
					<text class="cuIcon-titles text-orange"></text>
					审核
				</view>
				<view class="action pass">
					<view class="cu-form-group btn">
						<view>
							<button @click="pass('通过',item._id,index)" class="cu-btn round line-green ">通过</button>
							<button @click="pass('不通过',item._id,index)" class="cu-btn round line-red margin-left-sm">不通过</button>
						</view>
					</view>
				</view>
			</view>
			<view class="cu-card article no-card" @click="open(item)">
				<view class="cu-item shadow">
					<view class="title flex">
						<view class="listcard-header_image cu-avatar lg">
							<image v-if="!item.avatar" src="../../static/img/guo.jpg"></image>
							<image :src="item.avatar"></image>
						</view>
						<view style="margin-left: 4%;">{{item.name}}</view>
					</view>
					<view class="title">
						<view class="text-cut">{{item.title}}</view>
					</view>
					<view class="text-contents">
	
						<video style="margin: 0 auto;" v-if="item.video" :src="item.video" @click.stop></video>
						<view  v-if="!item.video">{{item.content}}</view>
					</view>
					<view class="time">
						<view>
							<view class="cu-tag bg-red light sm round">发表时间：</view>
							<view class="cu-tag  light sm round">{{item.time|unix2Time}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view style="margin: 25%  12%">
			<image v-if="show" src="../../static/img/空.png"></image>
		</view>


	</view>
</template>
<script>
	export default {
		data() {
			return {
				info: "",
				show: false
			}
		},
		async onLoad() {
			await this.$store.dispatch('initchecknum')
			this.info = this.$store.state.checknum.result.data
			if (!this.info.length) {
				this.show = true
			}
		},
		methods: {
			pass(value, id, index) {
				uni.showModal({
					title: "确定",
					content: `是否确定${value}`,
					success: (res) => {
						if (res.confirm) {
							uni.showLoading()
							uniCloud.callFunction({
								name: "upload_check",
								data: {
									value,
									id
								},
								success: (res) => {
									this.info.splice(index, 1)
									uni.showToast({
										title: "成功"
									})
								},
								fail(err) {
									console.log(err);
									uni.showToast({
										title: "失败请重试",
										icon: "none"
									})
								}
							})
						}
					}
				})
			},
			open(item) {
				console.log(item)
				const items = item;
				const params = {
					_id: items._id,
					name: items.name,
					avatar: items.avatar,
					time: items.time,
					title: items.title
				}
				this.$store.commit('changeComment', false)
				uni.navigateTo({
					url: '/pages/details/details?params=' + JSON.stringify(params)
				})
			},
			onPullDownRefresh() {
				uniCloud.callFunction({
					name: "get_content",
					data: {
						type: "no" //未审核帖子
					}
				}).then(res => {
					this.info = res.result.data
					uni.stopPullDownRefresh()
				})
			}
		}
	}
</script>

<style lang="scss">
	.pass {
		margin-right: 0 !important;
	}

	.pass .btn {
		padding-right: 5px !important;
	}

	.listcard-header_image {
		flex-shrink: 0;
		width: 60upx;
		height: 60upx;
		border-radius: 50%;
		overflow: hidden;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.flex {
		display: flex;
	}

	.list {
		margin-top: 2%;
	}

	.listcard-image_item {
		flex: 1;
		margin-left: 10px;
		width: 100%;
		padding: 0%;
		overflow: hidden;

		&:first-child {
			margin-left: 0;
		}

	}

	.time {
		margin-top: 4%;
		float: right;
	}

	.text-contents {
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 4;
		-webkit-box-orient: vertical;
		margin-left:14%
	}
</style>
